package com.zhangfei.stream;

import java.util.Arrays;
import java.util.List;

public class CountTest {
    public static void main(String[] args) {
        List<Student> students = Arrays.asList(
                new Student(1, "张三", 20),
                new Student(2, "李四", 22),
                new Student(3, "王五", 24)
        );

        long count = students.stream()
                .filter(s -> s.getAge() >= 21)
                .count();

        System.out.println("年龄大于等于21的学生数量：" + count);

        students.stream()
                .filter(s -> s.getAge() >= 21)
                .forEach(System.out::println);
    }
}
